from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.input import TextInput
from aiogram_dialog.widgets.kbd import Button, Start

from src.presentation.tg_bot.dialogs.getters.users import user_info_getter
from src.presentation.tg_bot.dialogs.widgets import LocaleText
from src.presentation.tg_bot.handlers import admin_start
from src.presentation.tg_bot.states import (
    BuyVPNSG,
    ClientSG,
    HelpSG,
    LanguageSG,
    MissingGeoSG,
    ProxySubscriptionSG,
    SelectProxySG,
    SoftProxySG,
    VPNRouterSG,
)

from ..profile.handlers import show_user_profile
from .handlers import register_user

start_window = Window(
    LocaleText("welcome", user="{event.from_user.username}"),
    Start(
        LocaleText("buy-proxy-btn"),
        id="buy_proxy_button",
        state=SelectProxySG.list_proxy_types,
    ),
    Start(
        LocaleText("test-proxy-btn"),
        id="test_proxy",
        state=SelectProxySG.list_proxy_types,
        data={"for_test": True},
        when=F["test_proxy_available"],
    ),
    Start(
        LocaleText("proxy-subscription-btn"),
        id="manage_proxy_subscription",
        state=ProxySubscriptionSG.show_info,
    ),
    Start(
        LocaleText("buy-vpn-btn"),
        id="buy_vpn_button",
        state=BuyVPNSG.show_info,
    ),
    Start(
        LocaleText("buy-vpn-router-btn"),
        id="vpn_router_btn",
        state=VPNRouterSG.show_info,
    ),
    Start(
        LocaleText("change-lang-btn"),
        id="languages",
        state=LanguageSG.list_of_languages,
    ),
    Button(LocaleText("profile-btn"), id="user_profile", on_click=show_user_profile),
    Button(
        LocaleText("admin-btn"),
        id="admin_panel",
        on_click=admin_start,
        when=F["is_admin"],
    ),
    Start(LocaleText("help-btn"), id="help", state=HelpSG.show_help_info),
    Start(LocaleText("soft-proxy-btn"), id="soft_proxy", state=SoftProxySG.show_info),
    Start(
        LocaleText("missing-geo-btn"),
        id="missing_geo",
        state=MissingGeoSG.show_missing_geo_msg,
    ),
    state=ClientSG.start,
    getter=user_info_getter,
)

reg_window = Window(
    LocaleText("enter-email"),
    TextInput("email_address", str, on_success=register_user),
    state=ClientSG.register,
)

start_dialog = Dialog(start_window, reg_window)
